package common

import (
	"context"
	"github.com/apache/rocketmq-client-go/v2/admin"
	"github.com/apache/rocketmq-client-go/v2/primitive"
	"github.com/pkg/errors"
)

func CreateTopic(config Config) error {
	rmqAdmin, err := admin.NewAdmin(admin.WithResolver(primitive.NewPassthroughResolver(config.Host)))
	if err != nil {
		return errors.Wrap(err, "ERR: fail to init a admin")
	}
	err = rmqAdmin.CreateTopic(
		context.Background(),
		admin.WithTopicCreate("dmsgo"),
		admin.WithReadQueueNums(3),
		admin.WithWriteQueueNums(3),
		admin.WithBrokerAddrCreate(config.Broker[0]),
	)
	if err != nil {
		return errors.Wrap(err, "ERR: fail to create topic")
	}
	return nil
}
